In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Great Bytelandish net of supermarkets asked you for writing a program simulating costs of the promotion being prepared.
The promotion has to obey the following rules:
Turnovers of the supermarket are very big, thus an assumption can be made, that at the end of every day, before taking out bills amounting to the greatest and the least sum, there are at least 2 bills in the ballot box.
Your task is to compute on the basis of information about prices on bills thrown to the ballot box on each day of promotion, what will be the total cost of prizes during the whole promotion.
Write a program which:
The first line of the standard input contains one positive integer , where , which is the duration of promotion in days.
Each of the next lines consists of a sequence of non-negative integers separated by single spaces. Numbers in the -th line of the file represent prices on bills thrown to the ballot box on the -th day of promotion. The first integer in the line is , , the number of bills from the day, and the next numbers are positive integers standing for the prices on bills; none of these numbers is greater than .
The total number of bills thrown to the ballot box during the whole promotion does not exceed .
The standard output should contain exactly one integer, which is equal to the total cost of prizes paid during the whole promotion.
For the input data:
5 3 1 2 3 2 1 1 4 10 5 5 1 0 1 2
the correct result is:
19
Task author: Tomasz Walen.